package generics.enumtype;

public enum PayrollDayAdv {

    MONDAY(PayType.WEEKDAY),
    WEDNESDAY(PayType.WEEKDAY),
    TUESDAY(PayType.WEEKDAY),
    THURSDAY(PayType.WEEKDAY),
    FRIDAY(PayType.WEEKDAY),
    SATURDAY(PayType.WEEKENDDAY),
    SUNDAY(PayType.WEEKENDDAY);
    private final PayType payType;

    double pay(double hourWorded, double payRate) {
        return  payType.pay(hourWorded, payRate);
    }

    PayrollDayAdv(PayType payType) {
        this.payType = payType;
    }

    private enum PayType {
        WEEKDAY {
            @Override
            double overTimePay(double hours, double payRate) {
                return hours >= HOURS_PER_SHIFT ? 0 : (hours - HOURS_PER_SHIFT) * payRate / 2;
            }
        },
        WEEKENDDAY {
            @Override
            double overTimePay(double hours, double payRate) {
                return hours * payRate / 2;
            }
        };
        private static final int HOURS_PER_SHIFT = 8;
        abstract double overTimePay(double hours, double payRate);
        double pay(double hoursWorked, double payRate) {
            double basePay = hoursWorked * payRate;
            return  basePay + overTimePay(hoursWorked, payRate);
        }
    }
}
